package com.tanhua.server.controller;

import com.tanhua.domain.vo.ContactVo;
import com.tanhua.domain.vo.MessageVo;
import com.tanhua.domain.vo.PageResult;
import com.tanhua.server.service.MessagesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 消息模块-控制层
 */
@RestController
@RequestMapping("/messages")
public class MessagesController {

    @Autowired
    private MessagesService messagesService;

    /**
     * 联系人添加
     */
    @RequestMapping(value = "/contacts", method = RequestMethod.POST)
    public ResponseEntity saveFriend(@RequestBody Map params) {
        long friendId = Long.parseLong(params.get("userId").toString());//需要添加好友id
        messagesService.saveFriend(friendId);
        return ResponseEntity.ok(null);
    }

    /**
     * 分页查询联系人
     */
    @RequestMapping(value = "/contacts", method = RequestMethod.GET)
    public ResponseEntity queryFriendPage(@RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "10") int pagesize, String keyword) {
        PageResult<ContactVo> pageResult = messagesService.queryFriendPage(page,pagesize,keyword);
        return ResponseEntity.ok(pageResult);
    }


    /**
     * 点赞列表 1  //评论类型，1-点赞，2-评论，3-喜欢
     */
    @RequestMapping(value = "/likes", method = RequestMethod.GET)
    public ResponseEntity queryLikesPage(@RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "10") int pagesize) {
        PageResult<MessageVo> pageResult = messagesService.messageCommentPage(page,pagesize,1);
        return ResponseEntity.ok(pageResult);
    }

    /**
     * 评论列表 2
     */
    @RequestMapping(value = "/comments", method = RequestMethod.GET)
    public ResponseEntity queryCommentsPage(@RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "10") int pagesize) {
        PageResult<MessageVo> pageResult = messagesService.messageCommentPage(page,pagesize,2);
        return ResponseEntity.ok(pageResult);
    }

    /**
     * 喜欢列表 3
     */
    @RequestMapping(value = "/loves", method = RequestMethod.GET)
    public ResponseEntity queryLovesPage(@RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "10") int pagesize) {
        PageResult<MessageVo> pageResult = messagesService.messageCommentPage(page,pagesize,3);
        return ResponseEntity.ok(pageResult);
    }



}
